﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ALiteTeam.PackageTracer.Core;

namespace ALiteTeam.PackageTracer.ViewModel
{
    public class ViewModelLocator
    {
        public static string BackgroundImage { get; set; }

        /// <summary>
        /// 初始化  在这里创建ViewModel  可以将多个ViewModel在这里一起创建
        /// </summary>
        public ViewModelLocator()
        {
            CreateMainPageViewModel();
            CreateComfirmOrderViewModel();
            CreateDetailsViewModel();
            CreateSelectorViewModel();
            CreateInputOrderViewModel();

            if (GalaSoft.MvvmLight.ViewModelBase.IsInDesignModeStatic == false)
            {
                BackgroundImage = Settings.Configuration.BackgroundImage;
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
            ClearComfirmOrderViewModel();
            ClearMainPageViewModel();
            ClearDetailsViewModel();
            ClearSelectorViewModel();
            ClearInputOrderViewModel();
            ClearSettingsViewModel();
        }

        #region 属性区域

        /// <summary>
        /// Gets the MainPageViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainPageViewModel MainPageViewModel
        {
            get
            {
                return MainPageViewModelStatic;
            }
        }
        
        /// <summary>
        /// Gets the ComfirmOrderViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public ComfirmOrderViewModel ComfirmOrderViewModel
        {
            get
            {
                return ComfirmOrderViewModelStatic;
            }
        }

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public DetailsViewModel DetailsViewModel
        {
            get
            {
                return DetailsViewModelStatic;
            }
        }

        /// <summary>
        /// Gets the SelectorViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public SelectorViewModel SelectorViewModel
        {
            get
            {
                return SelectorViewModelStatic;
            }
        }

        /// <summary>
        /// Gets the InputOrderViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public InputOrderViewModel InputOrderViewModel
        {
            get
            {
                return InputOrderViewModelStatic;
            }
        }

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public SettingsViewModel SettingsViewModel
        {
            get
            {
                return SettingsViewModelStatic;
            }
        }

        #endregion        

        #region 静态属性区域
        private static MainPageViewModel _MainPageViewModel;
        /// <summary>
        /// Gets the MainPageViewModel property.
        /// </summary>
        public static MainPageViewModel MainPageViewModelStatic
        {
            get
            {
                if (_MainPageViewModel == null)
                {
                    CreateMainPageViewModel();
                }

                return _MainPageViewModel;
            }
        }

        private static ComfirmOrderViewModel _ComfirmOrderViewModel;
        /// <summary>
        /// Gets the ComfirmOrderViewModel property.
        /// </summary>
        public static ComfirmOrderViewModel ComfirmOrderViewModelStatic
        {
            get
            {
                if (_ComfirmOrderViewModel == null)
                {
                    CreateComfirmOrderViewModel();
                }

                return _ComfirmOrderViewModel;
            }
        }

        private static DetailsViewModel _DetailsViewModel;
        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        public static DetailsViewModel DetailsViewModelStatic
        {
            get
            {
                if (_DetailsViewModel == null)
                {
                    CreateDetailsViewModel();
                }

                return _DetailsViewModel;
            }
        }

        private static SelectorViewModel _SelectorViewModel;
        /// <summary>
        /// Gets the SelectorViewModel property.
        /// </summary>
        public static SelectorViewModel SelectorViewModelStatic
        {
            get
            {
                if (_SelectorViewModel == null)
                {
                    CreateSelectorViewModel();
                }

                return _SelectorViewModel;
            }
        }

        private static InputOrderViewModel _InputOrderViewModel;
        /// <summary>
        /// Gets the InputOrderViewModel property.
        /// </summary>
        public static InputOrderViewModel InputOrderViewModelStatic
        {
            get
            {
                if (_InputOrderViewModel == null)
                {
                    CreateInputOrderViewModel();
                }

                return _InputOrderViewModel;
            }
        }

        private static SettingsViewModel _SettingsViewModel;
        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        public static SettingsViewModel SettingsViewModelStatic
        {
            get
            {
                if (_SettingsViewModel == null)
                {
                    CreateSettingsViewModel();
                }

                return _SettingsViewModel;
            }
        }

        #endregion
        
        #region Create静态方法

        /// <summary>
        /// Provides a deterministic way to create the MainPageViewModel property.
        /// </summary>
        public static void CreateMainPageViewModel()
        {
            if (_MainPageViewModel == null)
            {
                _MainPageViewModel = new MainPageViewModel();
            }
        }
        /// <summary>
        /// Provides a deterministic way to create the ComfirmOrderViewModel property.
        /// </summary>
        public static void CreateComfirmOrderViewModel()
        {
            if (_ComfirmOrderViewModel == null)
            {
                _ComfirmOrderViewModel = new ComfirmOrderViewModel();
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the ViewModelPropertyName property.
        /// </summary>
        public static void CreateDetailsViewModel()
        {
            if (_DetailsViewModel == null)
            {
                _DetailsViewModel = new DetailsViewModel();
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the SelectorViewModel property.
        /// </summary>
        public static void CreateSelectorViewModel()
        {
            if (_SelectorViewModel == null)
            {
                _SelectorViewModel = new SelectorViewModel();
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the InputOrderViewModel property.
        /// </summary>
        public static void CreateInputOrderViewModel()
        {
            if (_InputOrderViewModel == null)
            {
                _InputOrderViewModel = new InputOrderViewModel();
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the ViewModelPropertyName property.
        /// </summary>
        public static void CreateSettingsViewModel()
        {
            if (_SettingsViewModel == null)
            {
                _SettingsViewModel = new SettingsViewModel();
            }
        }

        #endregion

        #region Clear静态方法

        /// <summary>
        /// Provides a deterministic way to delete the MainPageViewModel property.
        /// </summary>
        public static void ClearMainPageViewModel()
        {
            _MainPageViewModel.Cleanup();
            _MainPageViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to delete the ComfirmOrderViewModel property.
        /// </summary>
        public static void ClearComfirmOrderViewModel()
        {
            _ComfirmOrderViewModel.Cleanup();
            _ComfirmOrderViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to delete the ViewModelPropertyName property.
        /// </summary>
        public static void ClearDetailsViewModel()
        {
            _DetailsViewModel.Cleanup();
            _DetailsViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to delete the SelectorViewModel property.
        /// </summary>
        public static void ClearSelectorViewModel()
        {
            _SelectorViewModel.Cleanup();
            _SelectorViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to delete the InputOrderViewModel property.
        /// </summary>
        public static void ClearInputOrderViewModel()
        {
            _InputOrderViewModel.Cleanup();
            _InputOrderViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to delete the ViewModelPropertyName property.
        /// </summary>
        public static void ClearSettingsViewModel()
        {
            _SettingsViewModel.Cleanup();
            _SettingsViewModel = null;
        }

        #endregion            
    }
}
